<?php


namespace app\erp\model;


use think\Db;
use think\Model;

class PikuanLogdb extends Model
{
    protected $pk = 'id';
    protected $name = 'pikuan_log';
    public $param = [];
    protected $append = ['username'];

    public function base($query)
    {
        if (isset($this->param['return_code']) && $this->param['return_code']) {
            $query->where('return_code', $this->param['return_code']);
        }
        if (isset($this->param['log_txt']) && $this->param['log_txt']) {
            $query->whereLike('log_txt', '%' . $this->param['log_txt'] . '%');
        }
    }

    public function getUsernameAttr($val,$row){
        if($row['admin_id']){
            return Db::name('member')->where('member_id',$row['admin_id'])->value('username');
        } else {
            return '';
        }
    }
}